﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyGeneric
{
    class Program
    {
        /// <summary>
        /// 泛型原理
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            Console.WriteLine("泛型初探");

            int iParameter = 12311321;
            DateTime dtParameter = DateTime.Now;
            People people = new People()
            {
                Id = 11,
                Name = "test"
            };

            Common.ShowInt(iParameter);
            Common.ShowDateTime(dtParameter);
            Common.ShowPeople(people);

            Console.WriteLine("----------------------ShowObject------------------------------");
            object test = "test";
            Common.ShowObject(iParameter);
            Common.ShowObject(dtParameter);
            Common.ShowObject(people);
            Common.ShowObject(test);

            Console.WriteLine("-------------------GenericClass---------------------------------");
            GenericClass.ShowT<int>(iParameter);
            GenericClass.ShowT<DateTime>(dtParameter);
            GenericClass.ShowT<People>(people);

            GenericClass.ShowT("no T , also can be called");

            Console.WriteLine("-------------------GenericConstraint---------------------------------");
            //GenericConstraint.Get<int>(3);   T 被限制了， 必须是 引用类型
            //泛型约束后，类型必须满足约束
            GenericConstraint.Get<string>("123");
            GenericConstraint.Get<People>(people);

            GenericConstraint.Query<int>(3);

            People p = new People()
            {
                Id = 100,
                Name = "albert"
            };
            GenericConstraint.SayHi<People>(p);

            Chinese chinese = new Chinese()
            {
                Id = 1,
                Name = "asdas",
                KongFu = "wwwww"
            };
            GenericConstraint.SayHi<People>(chinese);

            Console.Read();

        }
    }
}
